import 'package:safetymonitor/app/components/custom_modele/custom_multiple_bottom_sheet.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/ext/ext.dart';
import 'package:safetymonitor/app/data/common/choice_bean.dart';
import 'package:jiffy/jiffy.dart';

///特殊作业-自定义选择方法
///[selectTime] 时间选取
class CustomSelectFunction {
  /// 时间选取
  /// [onCallBack] 回调
  static selectTime({required Function(String) onCallBack}) async {
    final DateTime? startTime = await showDatePicker(
      context: Get.context!,
      initialDate: DateTime.now(),
      firstDate: DateTime(2000),
      lastDate: DateTime(2100),
    );
    if (startTime != null) {
      onCallBack(
          Jiffy.parseFromDateTime(startTime).format(pattern: 'yyyy-MM-dd'));
    }
  }

  /// 时间选取 精确到时分秒
  /// [onCallBack] 回调
  static selectDateTime(
      {required Function(String) onCallBack,
        String? helpText = '',
        int firstDateY = 2000,
        int firstDateM = 1,
        int firstDateD = 1,
        int firstDateH = 0,
        int firstDateMinute = 0,
        int firstDateSecond = 0,
        int lastDateY = 2100,
        int lastDateM = 1,
        int lastDateD = 1,
        int lastDateH = 0,
        int lastDateMinute = 0,
        int lastDateSecond = 0,
        String pattern = 'yyyy-MM-dd HH:mm:ss',
        bool isTimeStamp = false
      }) async {
    final DateTime? selectedDate = await showDatePicker(
        context: Get.context!,
        initialDate: DateTime.now(),
        firstDate: DateTime(firstDateY, firstDateM, firstDateD, firstDateH, firstDateMinute, firstDateSecond),
        lastDate:  DateTime(lastDateY, lastDateM, lastDateD, lastDateH, lastDateMinute, lastDateSecond),
        helpText: helpText
    );
    if (selectedDate != null) {
      final TimeOfDay? selectedTime = await showTimePicker(
        context: Get.context!,
        initialTime: TimeOfDay.now(),
      );
      if (selectedTime != null) {
        final DateTime selectedDateTime = DateTime(
          selectedDate.year,
          selectedDate.month,
          selectedDate.day,
          selectedTime.hour,
          selectedTime.minute,
        );
        onCallBack(isTimeStamp
            ? selectedDateTime.millisecondsSinceEpoch.toString()
            : Jiffy.parseFromDateTime(selectedDateTime).format(
            pattern: pattern));
      }
    }
  }

  ///底部弹窗-选择
  ///[onCallBack] 回调
  ///[dataList] 数据
  ///[checkedList] 已选中的数据
  ///[isMultiple] 是否多选
  ///[title] 标题
  static selectMultipleBottomSheet<T extends ChoiceBean>({
    required Function(List<T> data) onCallBack,
    required List<T> dataList,
    List<T>? checkedList,
    String? title,
    bool isMultiple = true,
  }) async {
    CustomEquipmentBottomSheet<T>(
      dataList: dataList,
      checkedList: checkedList ?? [],
      onConfirm: (value) {
        onCallBack(value);
      },
      title: title,
      isMultiple: isMultiple,
    ).showBottomSheetDialog();
  }
}
